﻿using aop_cache_Data;
using aop_cache_Entity;
using aop_cache_Entity.DTO;
using aop_cache_WebService;
using Infrastructure;
using Project.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace aop_cache_Background.Controllers
{
    public class HomeController : Controller
    {


        //
        // GET: /Home/

        public ActionResult Index()
        {
            using (ServiceProxy<IService1> proxy = new ServiceProxy<IService1>())
            {
                return View(proxy.Channel.GetWebManageUsers());
            }
        }

        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(WebManageUsersDTO entity)
        {

            //通过WCF获取远程数据,不走unity
            using (ServiceProxy<IService1> proxy = new ServiceProxy<IService1>())
            {
                proxy.Channel.InsertWebManageUsers(entity);
            }

            return View();
        }


        public ActionResult Edit(int id)
        {
            using (ServiceProxy<IService1> proxy = new ServiceProxy<IService1>())
            {
                return View(proxy.Channel.GetWebManageUsersByID(id));
            }
        }
        [HttpPost]
        public ActionResult Edit(FormCollection form, int id)
        {
            var entity = new WebManageUsersDTO();
            TryUpdateModel(entity);
            using (ServiceProxy<IService1> proxy = new ServiceProxy<IService1>())
            {
                proxy.Channel.UpdateWebManageUsers(entity);
            }
            return RedirectToAction("Index");
        }

        void entity_PropertyChanged(object sender, Domain.Core.PropertyChangeEventArgs e)
        {
            Logger.Core.LoggerFactory.Instance.Logger_Info(string.Format("从属性名：{0}，属性值：{1}", e.PropertyName, e.PropertyValue));
        }

        void entity_PropertyChanging(object sender, Domain.Core.PropertyChangeEventArgs e)
        {
            Logger.Core.LoggerFactory.Instance.Logger_Info(string.Format("变化到属性名：{0}，属性值：{1}", e.PropertyName, e.PropertyValue));
        }

    }

   
}
